﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBA.Common;
using DBA.Model;
using DBA.Data;
using DBA.Data.ADO;

namespace DBA.Web.PaperManage
{
    public partial class PaperSumAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request.Params["id"]))
                {
                    hidID.Value = RequestHelper.QueryString("id");
                    aSelectTeachers.InnerText = Request.Params["name"];
                    ModifyStudentInit();
                }
            }
        }

        private void ModifyStudentInit()
        {
            string id = hidID.Value;
            if (!VerificationHelper.IsNullOrEmpty<string>(id))
            {
                PaperWorkSum model = dal.ModifyData.GetEntity<PaperWorkSum>(id);
                if (!VerificationHelper.IsNullOrEmpty<PaperWorkSum>(model)) //如果学生对象不为空，那么对控件赋值
                {
                    ConvertHelper.ModelToControl<PaperWorkSum>(model, pan_tab.Controls);
                }               
            }            
              


        }

        DataAccessLibrary dal = CommonQuery.DataAccessLibrary;

        protected void lnkSave_Click(object sender, EventArgs e)
        {
            string demo = txt_pw_Demo.Value;
            string dd = txt_pw_PaperDetail.Value;
            PaperWorkSum modelPaperWorkSum = ConvertHelper.ControlToModel<PaperWorkSum>(pan_tab.Controls);
            if (hidID.Value.Equals(string.Empty))
            {              
                //studentInfo.EmployeeID = 10;
                hdResult.Value = dal.ModifyData.Insert<PaperWorkSum>(modelPaperWorkSum).ToString();
            }
            else 
            {
                modelPaperWorkSum.Pws_id = ConvertHelper.ToInt32(hidID.Value);              
                if (dal.ModifyData.Update<PaperWorkSum>(modelPaperWorkSum) == "0")
                {
                    hdResult.Value = "0";
                }
                else
                {
                    hdResult.Value = "1";
                }
            }
        }
    }
}